package mm.util;

import java.util.Arrays;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;

import mm.http.SystemListener;

public class DebuggableJdbcTemplate extends JdbcTemplate {

	public DebuggableJdbcTemplate(DataSource dataSource) {
		super(dataSource);
	}

	@Override
	public List queryForList(String sql, Object[] params) throws DataAccessException {
		if(SystemListener.isDebugging()){
			StringBuffer sb=new StringBuffer("Parameters: ");
			sb.append(Arrays.toString(params));
			LOG.debug(this.getClass(), sb.toString());
		}
		return super.queryForList(sql, params);
	}

	@Override
	public int update(String sql, Object[] params) throws DataAccessException {
		if(SystemListener.isDebugging()){
			StringBuffer sb=new StringBuffer("Parameters: ");
			sb.append(Arrays.toString(params));
			LOG.debug(this.getClass(), sb.toString());
		}
		return super.update(sql, params);
	}

	
	
}
